import os
import subprocess

# 定义git仓库列表，格式为：[("仓库地址", "分支"), ...]
# 如果分支为空字符串，则拉取默认分支
repositories = [
    ("https://gitee.com/haijun1998/spring-framework.git", ""),
    ("https://gitee.com/haijun1998/spring-boot.git", ""),
    ("https://gitee.com/haijun1998/mybatis-plus", ""),
    ("https://gitee.com/haijun1998/eureka.git", ""),
]

def clone_or_update_repo(repo_url, branch):
    repo_name = repo_url.split("/")[-1].replace(".git", "")
    if os.path.exists(repo_name):
        print(f"🔄 Updating {repo_name}...")
        os.chdir(repo_name)
        subprocess.run(["git", "pull"])
        os.chdir("..")
    else:
        print(f"📥 Cloning {repo_name}...")
        if branch:
            subprocess.run(["git", "clone", "-b", branch, repo_url])
        else:
            subprocess.run(["git", "clone", repo_url])

def main():
    for repo_url, branch in repositories:
        clone_or_update_repo(repo_url, branch)

if __name__ == "__main__":
    main()
